package com.atguigu.service.impl;

import com.atguigu.dao.BasicBehaviorDao;
import com.atguigu.dao.impl.BasicBehaviorDaoImpl;
import com.atguigu.pojo.BasicBehavior;
import com.atguigu.pojo.Page;
import com.atguigu.service.BasicBehaviorService;

import java.util.List;

public class BasicBehaviorServiceImpl implements BasicBehaviorService {
    BasicBehaviorDao basicBehaviorDao=new BasicBehaviorDaoImpl();
    @Override
    public void addBasicBehavior(BasicBehavior basicBehavior) {
        basicBehaviorDao.addBasicBehavior(basicBehavior);
    }

    @Override
    public void updateBasicBehavior(BasicBehavior basicBehavior) {
        basicBehaviorDao.updateBasicBehavior(basicBehavior);
    }

    @Override
    public void deleteBasicBehaviorById(String id) {
        basicBehaviorDao.deleteBasicBehaviorById(id);
    }

    @Override
    public BasicBehavior queryBasicBehaviorById(String id) {
        return basicBehaviorDao.queryBasicBehaviorById(id);
    }

    @Override
    public BasicBehavior queryBasicBehaviorByStatusMakeAndClientId(String clientId){
        return basicBehaviorDao.queryBasicBehaviorByStatusMakeAndClientId(clientId);
    }
    @Override
    public BasicBehavior queryBasicBehaviorByStatusMakeAndClientIdAndMainTaskId(String clientId,String mainTaskId){
        return basicBehaviorDao.queryBasicBehaviorByStatusMakeAndClientIdAndMainTaskId(clientId,mainTaskId);
    }
    @Override
    public BasicBehavior queryBasicBehaviorByStatusMakeAndClientIdAndDeployServiceModuleId(String clientId,String deployServiceModuleId){
        return basicBehaviorDao.queryBasicBehaviorByStatusMakeAndClientIdAndDeployServiceModuleId(clientId,deployServiceModuleId);
    }
    @Override
    public List<BasicBehavior> queryBasicBehaviors() {
        return basicBehaviorDao.queryBasicBehaviors();
    }

    @Override
    public Page page(Integer pageNo, Integer pageSize) {
        Page<BasicBehavior> page=new Page<>();
        page.setPagesize(pageSize);
        Integer pageTotalCount=basicBehaviorDao.queryForPageTotalCount();
        page.setPageTotalCount(pageTotalCount);
        Integer pageTotal=pageTotalCount/pageSize;
        if(pageTotalCount % pageSize >0){
            pageTotal++;//总条数,除以一页条数,大于0,页码数+1
        }
        page.setPageTotal(pageTotal);
        System.out.println("pageNo 原来是 is:"+pageNo);
        if(pageNo<1){//防止用户输入量太大
            pageNo=1;
        }else if(pageNo>pageTotal){
            pageNo=pageTotal;
        }
        page.setPageNo(pageNo);//当前页码
        System.out.println("pageNo 现在是 is:"+pageNo);
        System.out.println("pageTotal is:"+pageTotal);
        //要得到的是page的items
        Integer begin=(page.getPageNo()-1)*pageSize;
        List<BasicBehavior> items=basicBehaviorDao.queryForPageItems(begin,pageSize);
        page.setItems(items);
        return page;
    }
}
